package com.itboy.message.email.controller;


import com.itboy.message.email.domain.MsgEmailConfig;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.message.email.vo.MsgEmailConfigVo;
import com.itboy.message.email.service.IMsgEmailConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 邮箱配置Controller
 *
 * @author gssong
 * @date 2021-07-09
 */
@Api(value = "邮箱配置控制器", tags = {"邮箱配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/message/email/config")
public class MsgEmailConfigController extends BaseController {

    private final IMsgEmailConfigService iMsgEmailConfigService;


    /**
     * 获取邮箱配置详细信息
     */
    @ApiOperation("获取邮箱配置详细信息")
    @PreAuthorize("@ss.hasPermi('email:config:query')")
    @GetMapping("/{configId}")
    public AjaxResult<MsgEmailConfig> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("configId") Long configId) {
        return AjaxResult.success(iMsgEmailConfigService.getById(configId));
    }


    /**
     * 修改邮箱配置
     */
    @ApiOperation("修改邮箱配置")
    @PreAuthorize("@ss.hasPermi('email:config:edit')")
    @Log(title = "邮箱配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MsgEmailConfig msgEmailConfig) {
        return toAjax(iMsgEmailConfigService.updateById(msgEmailConfig) ? 1 : 0);
    }

	/**
	 * 发送邮件
	 */
	@ApiOperation("发送邮件")
	@PreAuthorize("@ss.hasPermi('email:config:edit')")
	@Log(title = "发送邮件", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping("/sendEmail")
	public AjaxResult<Void> sendEmail(@RequestBody MsgEmailConfigVo msgEmailConfigVo) {
		return toAjax(iMsgEmailConfigService.sendEmail(msgEmailConfigVo));
	}

}
